package com.kujawnode.utils;

import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @version 1.0
 * @Author kujaw
 * @Date 2025/7/9 14:51
 * @注释
 */
public class ResponseUtils {

    /**
     * 使用response,把结果写出到前端
     *
     * @param response
     * @param result
     */
    public static void write(HttpServletResponse response,String result){
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            writer.write(result);
            writer.flush();
        } catch (IOException e) {
            throw  new RuntimeException(e);
        }finally {
            if(writer != null){
                writer.close();
            }
        }
    }

}
